<?php
    require_once dirname(BASEPATH) . '/application/controllers/system/_init.php';
	
	class abs_search extends _init{
		function index(){
			$this->set_header_main();
			$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),
										'ค้นหาร้านกาแฟ' => base_url() . 'cafe/search'));	
			
			$types = $this->input->get('t');
			$keyword = $this->input->get('key');
			$province_id = $this->input->get('pv');
			$start_index = $this->input->get('p');
			
			if (empty($start_index))
				$start_index = 0;
			
			$display_length = 8;
			
			$this->load->model('local/data/cafe/mod_cafe');			
			if (!empty($types) || !empty($keyword) || !empty($province_id)){				
				$result = $this->mod_cafe->search_cafe($keyword, 0, $types, $province_id, ($start_index-1) * $display_length, $display_length);				
			} else
				$result = $this->mod_cafe->search_cafe(null, 0, null, null, ($start_index-1) * $display_length, $display_length);		
			
			$this->load->model('local/data/cafe/mod_cafe_type');
			$this->load->model('local/data/area/mod_province');
						
			$data_content_0['cafe_list'] = $result['result'];
			$data_content_0['display_length'] = $display_length;
			$data_content_0['cafe_type_list'] = $this->mod_cafe_type->get_cafe_type();
			$data_content_0['province_list'] = $this->mod_province->get_province_for_dropdownlist(true);
			$data_content_0['page_count'] = ceil($result['row_count'] / $display_length);
			$data_content_0['page_start_index'] = $start_index;				
						
			$this->template->write('content_1', $this->load->view('cafe/search/frm_search', $data_content_0, true));			
			$this->template->render();
		}
	}
?>